import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import get from '@dfeidao/atom-web/local/get';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import error from '@dfeidao/atom-web/msgbox/error';
import render from '@dfeidao/atom-web/render/render';
import hide_loading from '../../atom/hide-loading';
import show_loading from '../../atom/show-loading';
import p006 from './p006';
export default async function a016(fd: IFeidaoAiBrowserComponent, args: { currentTarget: HTMLElement }) {
	const page_name = fd.data.node.getAttribute('page-name');
	// 动态详情点赞/取消点赞
	const productid = get(fd, 'productid');
	const employee_no = get(fd, 'staff_no');
	const comment_numbering = args.currentTarget.getAttribute('reply_numbering');
	const reply_numbering = comment_numbering;
	const num = args.currentTarget.getAttribute('statistical_magnitude');
	const isaa = args.currentTarget.getAttribute('data-isa');
	let flag = parseInt(isaa, 10);
	let statistical_magnitude = parseInt(num, 10);
	try {
		show_loading();
		const res = await nodejs(page_name + '/s001', { employee_no, productid, comment_numbering, flag });
		hide_loading();
		if (res === 'success') {
			flag = (flag + 1) % 2;
			if (flag === 0) {
				statistical_magnitude = statistical_magnitude - 1;
			} else {
				statistical_magnitude = statistical_magnitude + 1;

			}
			const isa = flag;
			render(fd, { reply_numbering, isa, statistical_magnitude }, p006, 'p006' + comment_numbering, 'inner');
		} else {
			error('操作失败');
		}
		hide_loading();
	} catch (e) {
		hide_loading();
		error('操作失败');
	}
}
